package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.acticle.query.DestinationQuery;
import cn.wolfcode.luowowo.acticle.service.IDestinationService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/destination")
public class DestinationController {

    @Reference
    private IDestinationService destinationService;

    @RequestMapping("/list")
    public String list(Model m, @ModelAttribute("qo") DestinationQuery qo) {
        PageInfo query = destinationService.query(qo);
        m.addAttribute("pageInfo", query);
        m.addAttribute("toasts",destinationService.getToastById(qo.getParentId()));
        return "destination/list";
    }


    @RequestMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(Long id, boolean hot) {
        destinationService.changeHotValue(id, hot);
        return new AjaxResult();
    }

    @RequestMapping("/setInfo")
    @ResponseBody
    public Object setInfo(Long id,String info) {
        destinationService.setInfo(id,info);
        return new AjaxResult();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id) {
        destinationService.delete(id);
        return new AjaxResult();
    }
}
